﻿Shader "Unlit/CellWrite"
{
    Properties
    {
        [HideInInspector]
        _MainTex ("Texture", 2D) = "white" { }
        _CellValue ("CellValue", float) = 0
    }
    SubShader
    {

        Pass
        {
            Tags { "LightMode" = "MetaCell" }
            ZWrite off
            ZTest off
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct appdata
            {
                float4 vertex: POSITION;
                float2 uv: TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex: SV_POSITION;
                float2 uv: TEXCOORD0;
            };


            float4 _LandRect;
            half _CellValue;

            v2f vert (appdata v)
            {
                v2f o = (v2f)0;
                float3 positionWS = TransformObjectToWorld(v.vertex);
                float4 positionCS = float4(0, 0, 0, 1);
                positionCS.x = (positionWS.x - _LandRect.x) / (_LandRect.y - _LandRect.x) * 2. - 1.;
                positionCS.y = (1.0 - (positionWS.y - _LandRect.z) / (_LandRect.w - _LandRect.z)) * 2. - 1.;
                o.vertex = positionCS;
                o.uv = v.uv;
                return o;
            }

            half frag (v2f i) : SV_Target
            {
                return _CellValue;
            }

            ENDHLSL

        }
    }
}
